// pages/mine/picker/index.js
const App = getApp()
import Util from '../../../utils/util'

Page({
  data: {
    init: false,
    loading: false,
    CustomBar: App.Global.CustomBar,

    items: [],
   
  },

  onLoad() {
    wx.sub('ReloadPickerInfo', this, () => {
      this.execLoad()
    })
    this.execLoad()
  },
  onUnload() {
    wx.cancel('ReloadPickerInfo', this)

  },


  execLoad() {
    this.setData({
      loading: true
    })
    App.doPost({
      uri: '/app/user/picker/list',
      body: {

      },
      fnSucc: resp => {
        const data = resp.data.items
        data.forEach(item => {
          item.showMore = false
        })
        this.setData({
          init: true,
          loading: false,
          items: data
        })
      },
    })
  },
  // 跳转页面
  toPage(e) {
    wx.navigateTo({
      url: e.currentTarget.dataset.uri
    })
  },

  doDelete(e) {
    console.log("删除")
    let clk = e.currentTarget.dataset.clk
    Util.Dialog.confirm(`是否删除[]？`, () => {
      this.execDelete(clk.id)
    })
  },
  execDelete(id) {
    this.setData({
      loading: true
    })
    App.doPost({
      uri: '/app/user/picker/delete',
      body: {
        ids: [id]
      },
      fnSucc: () => {
        this.execLoad()
      }
    })
  },
  showButton(e) {
    const {
      index
    } = e.currentTarget.dataset;
    const items = [...this.data.items]
    const item = items[index]
    item.showMore = !item.showMore
    this.setData({
      items
    })
  },
})